import {
   reactive
 } from 'vue';
 // import {
 //   onPageScroll
 // } from '@dcloudio/uni-app'

 function useBounceFunc(bottomY){
   const state = reactive({
     startY: '',
     coverTransform: 'translateY(0)',
     coverTransition: ''
   });
   // let sT = 0;
   const moveH = (ev) => {
     // if (sT !== 0 && sT !== bottomY) return;
     let moveY = ev.touches[0].clientY,
       distance = moveY - state.startY;
     distance > 280 ? distance = 280 : null;
     distance < -280 ? distance = -280 : null;
     state.coverTransform = `translateY(${distance}rpx)`;
   };
   const startH = (ev) => {
     // if (sT !== 0 && sT !== bottomY) return;
     state.coverTransition = ''
     state.startY = ev.touches[0].clientY;
   };
   const endH = (ev) => {
     // if (sT !== 0 && sT !== bottomY) return;
     state.coverTransition = `transform 0.2s ease-in`;
     state.coverTransform = 'translateY(0)'
   };
   // onPageScroll((o) => {
   //   sT = o.scrollTop
   //   console.log(sT);
   // })
   
   return {
     state,
     moveH,
     startH,
     endH
   }
 }
 
 export default useBounceFunc;
